$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'qyxxddryhc/list',
        datatype: "json",
        colModel: [
            { label: 'id', name: 'id', index: "id", width: 45, key: true,hidden:true },
			{ label: '操作', name: 'btn', index: 'btn', width: 35,
				formatter:function (cellvalue, option, rowObject) {
					return  "<a class=\"btn btn-modify\" style=\"display: inline;\" onclick=\"vm.detail('" + rowObject.id + "')\">查询</a>";
				}
			},
			// { label: '企业代码', name: 'ryhcQydm', index: 'RYHC_QYDM', width: 80 },
			{ label: '企业名称', name: 'ryhcQymc', index: 'RYHC_QYMC', width: 80  },
			{ label: '登记序号', name: 'ryhcDjxh', index: 'RYHC_DJXH', width: 80 }, 
			{ label: '姓名', name: 'ryhcXm', index: 'RYHC_XM', width: 40 },
			{ label: '证件号码', name: 'ryhcZjhm', index: 'RYHC_ZJHM', width: 80 }, 
			 { label: '性别代码', name: 'ryhcXbdmName', index: 'RYHC_XBDM_NAME', width: 80 ,hidden:true},
			{ label: '性别', name: 'ryhcXbdmCode', index: 'RYHC_XBDM_CODE', width: 35 ,hidden:true},
			{ label: '出生日期', name: 'ryhcCsrqName', index: 'RYHC_CSRQ_NAME', width: 80 }, 
			 { label: '出生日期代码', name: 'ryhcCsrqCode', index: 'RYHC_CSRQ_CODE', width: 80 ,hidden:true},
			{ label: '民族', name: 'ryhcMzdmName', index: 'RYHC_MZDM_NAME', width: 35 ,hidden:true},
			 { label: '民族代码', name: 'ryhcMzdmCode', index: 'RYHC_MZDM_CODE', width: 80,hidden:true },
			// { label: '户口所在地区号', name: 'ryhcHkszdxzqhdmName', index: 'RYHC_HKSZDXZQHDM_NAME', width: 80 },
			// { label: '户口所在地区号代码', name: 'ryhcHkszdxzqhdmCode', index: 'RYHC_HKSZDXZQHDM_CODE', width: 80 },
			{ label: '户口所在地详址', name: 'ryhcHkszdxz', index: 'RYHC_HKSZDXZ', width: 80 ,hidden:true},
			 { label: '核查时间代码', name: 'ryhcHcsjCode', index: 'RYHC_HCSJ_CODE', width: 80 ,hidden:true },
			{ label: '核查时间', name: 'ryhcHcsjName', index: 'RYHC_HCSJ_NAME', width: 80 }, 
			{ label: '核查申请人', name: 'ryhcHcsqr', index: 'RYHC_HCSQR', width: 80,hidden:true },
			{ label: '核查申请人手机', name: 'ryhcHcsqrsj', index: 'RYHC_HCSQRSJ', width: 80 ,hidden:true},
        ],
		viewrecords: true,
        height: 365,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
        q:{

        },
		showList: true,
		showDetail: false,
		title: null,
		qyxxDdRyhc: {},
        ryhcMzdmName:[],
        cyryXbdmName:[{text:'男性',value:'1'},{text:'女性',value:'2'},{text:'未知',value:'3'}]
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.qyxxDdRyhc = {};
            $.post(baseURL + "sysdic/findMz/", function(r){
                vm.ryhcMzdmName = r.data;
            })
		},
		update: function (event) {
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
			vm.showList = false;
            vm.title = "修改";
            $.post(baseURL + "sysdic/findMz/", function(r){
                vm.ryhcMzdmName = r.data;
            });
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
            if ( vm.qyxxDdRyhc.ryhcDjxh ==null) {
                alert("登记序号不能为空！");
                return false;
            }
            if ( vm.qyxxDdRyhc.ryhcXm ==null) {
                alert("姓名不能为空！");
                return false;
            }
            vm.qyxxDdRyhc.ryhcCsrqName=$("#csdate").val();
            vm.qyxxDdRyhc.ryhcHcsjName=$("#hcdate").val();
			var url = vm.qyxxDdRyhc.id == null ? "qyxxddryhc/save" : "qyxxddryhc/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
			    contentType: "application/json",
			    data: JSON.stringify(vm.qyxxDdRyhc),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "qyxxddryhc/delete",
				    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get(baseURL + "qyxxddryhc/info/"+id, function(r){
                vm.qyxxDdRyhc = r.qyxxDdRyhc;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page,
                postData:{'name':vm.q.name}
            }).trigger("reloadGrid");
		},
		detail: function (id) {
			vm.title = "核查人员信息";
			vm.getInfo(id);
			vm.showList = false;
			vm.showDetail = true;
		}
	}
});